import Vue from "vue";

import Cookies from "js-cookie";

import Element from "element-ui";
import "./assets/styles/element-variables.scss";
Element.Dialog.props.closeOnClickModal.default = false;
Element.Drawer.props.wrapperClosable.default = false;
Element.Dialog.props.modalAppendToBody.default = false;
Element.Drawer.props.modalAppendToBody.default = false;

import "@/assets/styles/ruoyi.scss"; // ruoyi css
// 系统全局通用样式
import "@/assets/styles/common.scss"; // common css
import App from "./App";
import store from "./store";
import router from "./router";
import directive from "./directive"; // directive
import plugins from "./plugins"; // plugins
import { download } from "@/utils/request";

import "./assets/icons"; // icon
import "./assets/iconfont/iconfont.css"; // iconfont
import "./permission"; // permission control
import { getDicts } from "@/api/system/dict/data";
import { getConfigKey } from "@/api/system/config";
import {
  parseTime,
  resetForm,
  addDateRange,
  addDateRange2,
  addDateRange3,
  selectDictLabel,
  selectDictLabels,
  handleTree,
  handleParams,
  handleParams2,
  dicthandleTree,
  handleFormErr,
  blobFileDownload,
  getMeauList,
} from "@/utils/ruoyi";

// 分页组件
import Pagination from "@/components/Pagination";
// 自定义表格工具组件
import RightToolbar from "@/components/RightToolbar";
// 文件上传组件
import FileUpload from "@/components/FileUpload";
// 图片上传组件
import ImageUpload from "@/components/ImageUpload";
// 图片预览组件
import ImagePreview from "@/components/ImagePreview";
// 字典标签组件
import DictTag from "@/components/DictTag";
// 头部标签组件
import VueMeta from "vue-meta";
// 字典数据组件
import DictData from "@/components/DictData";
//暂无数据
import noData from "@/components/noData";
//暂无搜索结果
import noResult from "@/components/noResult";

// tab页
import selectTab from "@/views/components/selectTab";
Vue.component("selectTab", selectTab);

import tabBar from "@/components/TabBar/tabBar.vue";
import tabPane from "@/components/TabBar/tabPane.vue";
Vue.component("tab-bar", tabBar);
Vue.component("tab-pane", tabPane);

import titleCard from "@/components/TitleCard/index.vue";
Vue.component("title-card", titleCard);

import cardGrid from "@/components/CardGrid/cardGrid.vue";
Vue.component("card-grid", cardGrid);

import "./utils/rem";

// fixed 顶部移动
function addHandleScroll2() {
  let navbar = document.getElementById("headerboxId");
  navbar.style.left = -document.getElementById("app").scrollLeft + "px";
}
Vue.prototype.$addHandleScroll2 = addHandleScroll2;
// 处理element-ui内联样式px2rem,全局挂载
function px2rem(px) {
  if (/%/gi.test(px)) {
    // 有百分号%，特殊处理，表述pc是一个有百分号的数，比如：90%
    return px;
  } else {
    return parseFloat(px) / 14 + "rem";
  }
}
Vue.prototype.$px2rem = px2rem;

Vue.prototype.$getMeauList = getMeauList;

import onlyNumber from "@/directive/el-input";
Vue.use(onlyNumber);

import $ from "jquery";
Vue.prototype.$ = $;
window.$ = $;

import Print from "vue-print-nb";
Vue.use(Print);

// 引入swiper start
import VueAwesomeSwiper from "vue-awesome-swiper";
import "swiper/css/swiper.css";
Vue.use(VueAwesomeSwiper /* { default options with global component } */);
// 引入swiper end

import Clipboard from "clipboard";
function copyTxt(e, text, msg) {
  // 复制
  const clipboard = new Clipboard(e.target, { text: () => text });
  clipboard.on("success", (e) => {
    this.$message({
      type: "success",
      message: msg ? msg : "复制成功",
      // offset: 60,
      duration: 1500,
    });
    // 释放内存
    clipboard.off("error");
    clipboard.off("success");
    clipboard.destroy();
  });
  clipboard.on("error", (e) => {
    // 不支持复制
    this.$message({
      type: "waning",
      message: "该浏览器不支持自动复制",
      // offset: 60,
      duration: 1500,
    });
    // 释放内存
    clipboard.off("error");
    clipboard.off("success");
    clipboard.destroy();
  });
  clipboard.onClick(e);
}
Vue.prototype.$copyTxt = copyTxt;

//鼠标拖拽排序
let draggedIndex = null;
function onDragStart(event, index) {
  draggedIndex = index;
  event.target.style.opacity = 0.5;
}
Vue.prototype.$onDragStart = onDragStart;
function onDragEnd(event) {
  event.target.style.opacity = "";
  draggedIndex = null;
}
Vue.prototype.$onDragEnd = onDragEnd;
function onDragEnter(event, index, list) {
  if (draggedIndex === null || draggedIndex === index) {
    return;
  }
  const draggedItem = list[draggedIndex];
  list.splice(draggedIndex, 1);
  list.splice(index, 0, draggedItem);
  draggedIndex = index;
}
Vue.prototype.$onDragEnter = onDragEnter;

// 引入富文本编辑器开始
// 1.百度编辑器
import "../public/UEditor/ueditor.config";
import "../public/UEditor/ueditor.all.js";
import "../public/UEditor/lang/zh-cn/zh-cn.js";
import "../public/UEditor/themes/default/css/ueditor.css";
import VueUeditorWrap from "vue-ueditor-wrap"; // ES6 Module
Vue.component("vue-ueditor-wrap", VueUeditorWrap);

import selectLazyLoad from "./directive/select-load-more"; //引入
Vue.use(selectLazyLoad); // 使用自定义指令

// // 2.wangEditor编辑器 打开后IE11报错，(不兼容)
// import '@wangeditor/editor/dist/css/style.css'
// // wangEditor 上传附件 插件start
// import { Boot } from '@wangeditor/editor'
// import attachmentModule from '@wangeditor/plugin-upload-attachment'
// Boot.registerModule(attachmentModule)
// // wangEditor 上传附件 插件end
// import wangEditor from '@/components/wangEditor'
// Vue.component('wangEditor', wangEditor)//注册全局组件方便使用
// 引入富文本编辑器结束

import filters from "@/filter";
Vue.use(filters);

import moment from "moment";
Vue.prototype.$moment = moment;

import _ from "lodash";
Vue.prototype._ = _;

import VueCompositionAPI from "@vue/composition-api";
Vue.use(VueCompositionAPI);

// 全局注册组件

import VueDragResize from "vue-drag-resize";
Vue.component("vue-drag-resize", VueDragResize);

import VueResize from "vue-resize";
Vue.use(VueResize);

import * as echarts from "echarts";
Vue.prototype.$echarts = echarts;

// 全局方法挂载
Vue.prototype.getDicts = getDicts;
Vue.prototype.getConfigKey = getConfigKey;
Vue.prototype.parseTime = parseTime;
Vue.prototype.resetForm = resetForm;
Vue.prototype.addDateRange = addDateRange;
Vue.prototype.addDateRange2 = addDateRange2;
Vue.prototype.addDateRange3 = addDateRange3;
Vue.prototype.selectDictLabel = selectDictLabel;
Vue.prototype.selectDictLabels = selectDictLabels;
Vue.prototype.download = download;
Vue.prototype.handleTree = handleTree;
Vue.prototype.dicthandleTree = dicthandleTree;
Vue.prototype.blobFileDownload = blobFileDownload;
Vue.prototype.handleFormErr = handleFormErr;
Vue.prototype.handleParams = handleParams;
Vue.prototype.handleParams2 = handleParams2;
// 全局组件挂载
Vue.component("DictTag", DictTag);
Vue.component("Pagination", Pagination);
Vue.component("RightToolbar", RightToolbar);
Vue.component("FileUpload", FileUpload);
Vue.component("ImageUpload", ImageUpload);
Vue.component("ImagePreview", ImagePreview);
Vue.component("noData", noData);
Vue.component("noResult", noResult);

Vue.use(directive);
Vue.use(plugins);
Vue.use(VueMeta);
DictData.install();

Vue.prototype.$eventBus = new Vue();

/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online! ! !
 */

import "@/assets/styles/index.scss"; // global css
Vue.use(Element, {
  size: Cookies.get("size") || "mini", // set element-ui default size
});

Vue.config.productionTip = false;

new Vue({
  // el: '#app',
  router,
  store,
  render: (h) => h(App),
}).$mount("#app");

window._AMapSecurityConfig = {
  securityJsCode: "e16985d5d55a125653eac47b2d5f98f1",
};
